clear 

* set directory 
* cd "directory"

* set paths
global datafolder "data"
global outputfolder "output"

********************************************************************************
*			Table 3: Lagged interest rates
********************************************************************************

	use "$datafolder\maindata.dta", clear

	keep if datem >= 660
	
	global cvars "OROA lDeposits lTotalAssets ratio_CurrentLiabilities "
	global loanChars "maturity_range has_coll_m_any lbalance"
	
	label variable actual_rate "Actual Rate"
	label variable theoretical_rate "Breakeven Rate"
	label variable OROA "OROA"
	label variable lDeposits "Deposits"
	label variable lTotalAssets "Assets"
	label variable ratio_CurrentLiabilities "Liabilities/Assets"
	label variable maturity_range "Maturity"
	label variable has_coll_m_any "Collateral"
	label variable lbalance "Loan Amount"
	
	label variable avgAR_l1 "Actual Rate\$_{t-1}$"
	
		estimates clear
		
		* Column 1: AR ~ ThR
		quietly reg actual_rate c.theoretical_rate avgAR_l1, ///
		cluster(customerid)
		quietly estadd local hasq "No"
		quietly estadd local hasind "No"
		quietly estadd local hasfirm "No"
		estimates store M1
		
		* Column 2: AR ~ ThR + quarter FE
		quietly reghdfe actual_rate c.theoretical_rate avgAR_l1, ///
		abs(dateq) cluster(customerid)
		estimates store M2
		quietly estadd local hasq "Yes"
		quietly estadd local hasind "No"
		quietly estadd local hasfirm "No"
		
		* Column 3: AR ~ ThR + quarter FE + firm controls
		quietly reghdfe actual_rate c.theoretical_rate $cvars avgAR_l1, ///
		abs(dateq) cluster(customerid)
		quietly estadd local hasq "Yes"
		quietly estadd local hasind "No"
		quietly estadd local hasfirm "No"
		estimates store M3
		
		* Column 4: AR ~ ThR + quarter FE + firm controls + loan controls
		quietly reghdfe actual_rate c.theoretical_rate $cvars $loanChars ///
		avgAR_l1, abs(dateq) cluster(customerid)
		quietly estadd local hasq "Yes"
		quietly estadd local hasind "No"
		quietly estadd local hasfirm "No"
		estimates store M4
		
		* Column 5: AR ~ ThR + quarter FE + firm controls + loan controls + industry FE
		quietly reghdfe actual_rate c.theoretical_rate $cvars $loanChars ///
		avgAR_l1, abs(dateq Industry) cluster(customerid)
		quietly estadd local hasq "Yes"
		quietly estadd local hasind "Yes"
		quietly estadd local hasfirm "No"
		estimates store M5
		
		* Column 6: AR ~ ThR + quarter FE + firm FE + loan controls
		quietly reghdfe actual_rate c.theoretical_rate $loanChars avgAR_l1, ///
		abs(firmid dateq) cluster(customerid)
		quietly estadd local hasq "Yes"
		quietly estadd local hasind "No"
		quietly estadd local hasfirm "Yes"
		estimates store M6
		
		esttab * using "$outputfolder\table_3.tex", replace  ///
		se r2 label nomtitles  b(3) se(3) r(3) ///
		star(* 0.1 ** 0.05 *** 0.01) ///
		noomitted noconstant nonotes substitute(\_ _) ///
		scalars("hasq Quarter FE" "hasind Industry FE" "hasfirm Firm FE")
	
